package com.hong.service_cart.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hong.fy_common_commomutil.common.result.Result;
import com.hong.fy_model.model.cart.CartEntity;
import com.hong.fy_model.model.cart.ProductCartRelationEntity;
import com.hong.fy_model.model.product.ProductEntity;
import com.hong.fy_model.model.user.UserEntity;
import com.hong.fy_model.vo.cart.CartVo;
import com.hong.service_cart.service.CartService;
import com.hong.service_cart.service.ProductCartRelationService;
import com.hong.service_product_client.ProductFeignClient;

import com.hong.service_user_client.UserFeignClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 *
 *
 * @author wqh
 * @email 1601709391@qq.com
 * @date 2022-06-16 21:42:56
 */
@RestController
@RequestMapping("/cart")
@Api(tags = "购物车-商品")
public  class ProductCartRelationController {
    @Autowired
    private ProductCartRelationService productCartRelationService;
    @Autowired
    private CartService cartService;


    @ApiOperation(value = "新增商品进入购物车", notes = "新增商品进入购物车")
    @PostMapping("/auth/addProduct")
    public Result addProductRe(@RequestBody CartVo cartVo) {
        Map<String, String> map = productCartRelationService.addProductRE(cartVo);
        return Result.build(Integer.valueOf(map.get("code")), map.get("msg"));
    }


    @ApiOperation(value = "删除购物车商品", notes = "删除购物车商品")
    @PostMapping("/auth/deleteProduct")
    public Result deleteProductRe(@RequestBody CartVo cartVo) {
        Boolean b = productCartRelationService.deleteProductRe(cartVo);
        if (b) {
            return Result.ok("");
        } else {
            return Result.fail( "删除失败");
        }
    }
    @ApiOperation(value = "根据购物车ID查询所有数据")
    @PostMapping("/auth/getAllList")
    public Result getAllList(@RequestBody CartEntity cartEntity) {

        List<ProductCartRelationEntity> list = productCartRelationService.getAllList(cartEntity);
        return Result.ok(list);
    }

//    @ApiOperation(value = "查询分页数据")
//    @PostMapping("productCartRelation/listByPage")
//
//    public DataResult findListByPage(@RequestBody ProductCartRelationEntity productCartRelation){
//        Page page = new Page(productCartRelation.getPage(), productCartRelation.getLimit());
//        LambdaQueryWrapper<ProductCartRelationEntity> queryWrapper = Wrappers.lambdaQuery();
//        //查询条件示例
//        //queryWrapper.eq(ProductCartRelationEntity::getId, productCartRelation.getId());
//        IPage<ProductCartRelationEntity> iPage = productCartRelationService.page(page, queryWrapper);
//        return DataResult.success(iPage);
//    }

}
